<?php

declare(strict_types=1);

namespace App\Request;

use Hyperf\Validation\Request\FormRequest;

class AdminRequest extends FormRequest
{
    protected $scenes = [
        'create' => ['role_ids','username','password','realname'],
        'update' => ['id','role_ids','username', 'realname'],
    ];


    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'role_ids' =>'required',
            'username'=>'required|max:16',
            'password'=>'required|min:8'
        ];
    }

    /**
     * 获取已定义验证规则的错误消息
     */
    public function messages(): array
    {
        return [
            'role_ids.required' => '请选择所属角色',
            'username.required' => '用户名必填',
            'username.max' => '用户名最大16个字符',
            'password.required'  => '密码必填',
            'password.min'  => '密码最小8个字符'
        ];
    }
}
